package com.frikinet.lifeguard.tests;

import java.awt.EventQueue;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JFrame;

import org.lobobrowser.html.UserAgentContext;
import org.lobobrowser.html.gui.HtmlPanel;
import org.lobobrowser.html.parser.DocumentBuilderImpl;
import org.lobobrowser.html.parser.InputSourceImpl;
import org.lobobrowser.html.test.SimpleHtmlRendererContext;
import org.lobobrowser.html.test.SimpleUserAgentContext;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class LocalHtmlTest
{
	public static void main(String args[]) throws SAXException, IOException
	{
		//sets log level
		Logger.getLogger("org.lobobrowser").setLevel(Level.WARNING);
		
		UserAgentContext uaContext = new SimpleUserAgentContext();
		DocumentBuilderImpl buider = new DocumentBuilderImpl(uaContext);
		
		//una vez creado el builder, leo el documento de local
		File file = new File("test.html");
		FileReader reader = new FileReader(file);
		InputSourceImpl input = new InputSourceImpl(reader, file.toURI().toString());
		Document doc = buider.parse(input);
		reader.close();
		
		HtmlPanel panel = new HtmlPanel();
		panel.setDocument(doc, new SimpleHtmlRendererContext(panel, uaContext));
		
		final JFrame frame = new JFrame("Hello world!");
		frame.getContentPane().add(panel);
		
		EventQueue.invokeLater(new Runnable()
		{
			public void run()
			{
				frame.pack();
				frame.setVisible(true);
			}
		});
	}
}
